package com.itheima.homework01.listdemo02;

import java.util.ArrayList;

public class ArrayListDemo2 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        int index = listTest(list,2);
        System.out.println(index);
    }

    private static int listTest(ArrayList<Integer> list, Integer num) {
        for (int i = 0; i < list.size(); i++) {
            if (num.equals(list.get(i))) {
                return i;
            }
        }
        return -1;

    }
}
